package com.pinda.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pinda.base.entity.PdTransportLine;
import com.pinda.commonutils.Page;
import com.pinda.commonutils.Result;
import com.pinda.commonutils.StatusCode;

import com.pinda.commonutils.utils.Constant;
import com.pinda.mapper.PdTransportLineMapper;
import com.pinda.service.IPdTransportLineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 线路表 服务实现类
 * </p>
 *
 * @author lc
 * @since 2023-06-14
 */
@Service
public class PdTransportLineServiceImpl extends ServiceImpl<PdTransportLineMapper, PdTransportLine> implements IPdTransportLineService {

    @Autowired
    PdTransportLineMapper pdTransportLineMapper;

    @Override
    public List<PdTransportLine> findAll(List<String> ids, String agencyId, List<String> agencyIds) {
        LambdaQueryWrapper<PdTransportLine> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (ids != null && ids.size() > 0) {
            lambdaQueryWrapper.in(PdTransportLine::getId, ids);
        }
        if (StringUtils.isNotEmpty(agencyId)) {
            lambdaQueryWrapper.eq(PdTransportLine::getAgencyId, agencyId);
        }
        if (agencyIds != null && agencyIds.size() > 0) {
            lambdaQueryWrapper.in(PdTransportLine::getAgencyId, agencyIds);
        }
        lambdaQueryWrapper.eq(PdTransportLine::getStatus, Constant.DATA_DEFAULT_STATUS);
        lambdaQueryWrapper.orderBy(true, false, PdTransportLine::getId);
        return baseMapper.selectList(lambdaQueryWrapper);
    }
    @Override
    public Result queryPageTransportLine(Page<PdTransportLine> page) {
        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        PdTransportLine search = page.getSearch();
        QueryWrapper queryWrapper = new QueryWrapper();
        if(search.getLineNumber()!=null&& !search.getId().equals("")){
            queryWrapper.like("line_number",search.getLineNumber());
        }
        if(search.getName()!=null&& !search.getId().equals("")){
            queryWrapper.like("name",search.getName());
        }
        if(search.getTransportLineTypeId()!=null&& !search.getTransportLineTypeId().equals("")){
            queryWrapper.like("transport_line_type_id",search.getTransportLineTypeId());
        }
        PageInfo pageInfo = new PageInfo(this.pdTransportLineMapper.selectList(queryWrapper));
        if(pageInfo!=null){
            return new Result(true, StatusCode.OK,"成功",pageInfo);
        }

        return new Result(true, StatusCode.ERROR,"失败",pageInfo);
    }
}
